package com.chaoyong.higo.adapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.chaoyong.higo.R;
import com.chaoyong.higo.bean.WiningGoodsBean;
import com.chaoyong.higo.utils.Values;
import com.chaoyong.higo.utils.ViewHolder;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ZuixinjiexiaoAdapter extends BaseAdapter {

	private Activity act;
	private List<WiningGoodsBean.DataEntity.ListEntity> datas;
	private LayoutInflater inflater;
	
	private ImageView image,head;
	private TextView username,times,price,time;
	
	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	public ZuixinjiexiaoAdapter(Activity act, List<WiningGoodsBean.DataEntity.ListEntity> datas) {
		// TODO Auto-generated constructor stub
		this.act = act;
		this.datas = datas;
		inflater = LayoutInflater.from(act);
	}
	
	public void changeDatas(List<WiningGoodsBean.DataEntity.ListEntity> datas){
		this.datas = datas;
		this.notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return datas == null ? 0 : datas.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(convertView == null){
			convertView = inflater.inflate(R.layout.item_newset_goods, null);
		}
		image = ViewHolder.get(convertView, R.id.iv_newset_image);
		head = ViewHolder.get(convertView, R.id.newset_user_headimage);
		username = ViewHolder.get(convertView, R.id.newset_user_name);
		times = ViewHolder.get(convertView, R.id.newset_how_times);
		price = ViewHolder.get(convertView, R.id.newset_goods_price);
		time = ViewHolder.get(convertView, R.id.newset_details_time);
		if(datas.get(position).getCover_img().get(0) == null){
			image.setImageResource(R.drawable.account_pic_default);
		}else{
			ImageLoader.getInstance().displayImage(Values.BASE_IMAGE_URL +datas.get(position).getCover_img().get(0), image);
		}
		
		if(datas.get(position).getUid_portrait() == null){
			head.setImageResource(R.drawable.head_image);
		}else{
			ImageLoader.getInstance().displayImage(Values.BASE_IMAGE_URL +datas.get(position).getUid_portrait(), head);
		}
		username.setText(datas.get(position).getUser_name());
		times.setText(datas.get(position).getBuy_num());
		price.setText(datas.get(position).getGoods_price());
		time.setText(sdf.format(new Date(Long.parseLong(datas.get(position).getLottery_time()) * 1000l)));
		return convertView;
	}
	
	

}
